package com.itita.ww2.handler.requesthandler.alliance;

import java.sql.SQLException;

import com.itita.ww2.core.MessageHandler;
import com.itita.ww2.core.WW2Exception;
import com.itita.ww2.enums.WW2ExceptionCode;
import com.itita.ww2.game.alliance.AllianceService;
import com.itita.ww2.game.user.UserService;
import com.itita.ww2.model.user.UserProfile;
import com.itita.ww2.utils.handler.IRequestOper;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;

/**
 * 查询本联盟玩家 支持分页查询 支持查询在线玩家
 * 
 * @author NorthLan
 *
 */
public class AlListUser implements IRequestOper {
	@Override
	public boolean execute(String requestCMD, User user, ISFSObject params) throws WW2Exception, SQLException {
		UserProfile userProfile = UserService.getInstance().getUserProfile(user);
		String aid = null;
		if (params.containsKey("aid")) {
			aid = params.getUtfString("aid");
		} else {
			if (userProfile.isJoinAlliance()) {
				aid = userProfile.getAid();
			} else {
				throw new WW2Exception(WW2ExceptionCode.ALLIANCE_HAS_NOT_JOIN);
			}
		}
		int page = params.getInt("page");
		ISFSObject backObj = AllianceService.getAllAllianceUserByAid(aid, page);
		MessageHandler.getInstance().sendMsg(requestCMD, backObj, user, null, true);
		return true;
	}

}
